package com.sciencep.pro.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sciencep.pro.core.dao.RoleMapper;
import com.sciencep.pro.core.domain.dto.dropdown.RoleSelectVO;
import com.sciencep.pro.core.domain.dto.role.RoleTO;
import com.sciencep.pro.core.domain.entity.Role;
import com.sciencep.pro.core.service.IRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Sciencep
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public List<RoleTO> getRoleList(Role role) {
        return roleMapper.getRoleList(role);
    }

    @Override
    public List<Role> getRoleGroupList() {
        return roleMapper.getRoleGroupList();
    }

    @Override
    public List<Role> getRoleNameByGroupId(Role role) {
        return roleMapper.getRoleNameByGroupId(role);
    }

    @Override
    public List<RoleSelectVO> getRoleSelectVOByGroupId(String groupId) {

        if(StringUtils.isEmpty(groupId)){
            return new ArrayList<>();
        }
        return baseMapper.getRoleSelectVOByGroupId(groupId);
    }

    @Override
    public List<Role> getRoleByUserId(String userId) {


        return baseMapper.getRoleByUserId(userId);
    }

    @Override
    public void delGroup(String groupId) {
        baseMapper.delGroup(groupId);
    }

    @Override
    public void delRole(String roleId) {
        baseMapper.delRole(roleId);
    }
}
